package com.itheima.pinkman.mapper;

import com.itheima.pinkman.pojo.ServiceInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface RegistryMapper extends Mapper<ServiceInfo> {
    @Select("select * from tb_provider where appName=#{appName}")
    List<ServiceInfo> findByAppName(String appName);

    @Delete("delete from tb_provider where appName=#{appName}")
    void deleteByAppName(String appName);

    @Update("update tb_provider set updateTime=#{updateTime},serviceId=#{serviceId} where appName=#{appName}")
    void updateByRenew(ServiceInfo serviceInfo);

    @Select("select * from tb_provider")
    List<ServiceInfo> findAllService();

    @Update("CREATE TABLE IF NOT EXISTS TB_PROVIDER(ip VARCHAR(50),PORT INT(6),appName VARCHAR(50),serviceId VARCHAR(100),updateDate BIGINT(100),createTime DATE)")
    void ifNotExistCreateDb();
}
